//
//  FQAuditView.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/12.
//

import UIKit

class FQAuditView: UIView {
    var failBlock : (()->Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let backImage = UIImageView(imageString: "icon_audit")
        addSubview(backImage)
        
        backImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(64)
        }
        
        let animateImage = UIImageView()
        animateImage.animationImages = (0...23).map({ i in
            UIImage(named: String(format: "icon_%d", i + 1))!
        })
        animateImage.animationDuration = 2
        animateImage.animationRepeatCount = 0
        animateImage.contentMode = .scaleAspectFill
        backImage.addSubview(animateImage)
        
        animateImage.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.size.equalTo(80)
        }
        
        let titleLb = QMUILabel(font: .rSFont(20), textColor: .color51)
        titleLb.text = "额度评估中"
        addSubview(titleLb)
        
        titleLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(backImage.snp.bottom).offset(24)
        }
        
        let subTitleLb = QMUILabel(font: .rSFont(14), textColor: .qmui_color(withHexString: "898991")!)
        subTitleLb.text = "您的额度正在评估中，请您耐心等待"
        addSubview(subTitleLb)
        
        subTitleLb.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(titleLb.snp.bottom).offset(14)
        }
    
        animateImage.startAnimating()
        
        perform(#selector(showFail), with: nil, afterDelay: 2)
    }
    
    @objc func showFail() {
        isHidden = true
        failBlock?()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
